package com.ftg.learn.mapper;

import com.ftg.learn.entity.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

/**
 * @author kangjx
 * @createTime 2022/11/25
 */
public class CallStudent2Mapper {

    /**
     * 我们可以通过接口  + sqlmapper.xml 的方式开发，要求是什么？sqlmapper namespace 要是一个真实的接口
     *   1 ：  路径 要完成正确
     *   2 : sql语句的id要与路径对应的方法完全一致
     *   3 : 接口里面方法不能重载
     * @param args
     */
    public static void main(String[] args) {
        String path = "mybatisconfig.xml";

        try {
            Reader reader = Resources.getResourceAsReader(path);

            SqlSessionFactory ssf = new SqlSessionFactoryBuilder().build(reader);

            SqlSession session = ssf.openSession();

            StudentMapper2 studentMapper2 = session.getMapper(StudentMapper2.class);
            System.out.println(studentMapper2.show1());

            session.commit();
            session.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
